﻿<%@ Page Language="C#" MasterPageFile="~/Frame.Master" AutoEventWireup="true" Codebehind="SysFuncOperates.aspx.cs"
    Inherits="BaseSystem._System.SysFuncOperates" Title="Search Function Operates Page" %>

<%@ Import Namespace="Auto.Data.Systems.Model" %>
<%@ Register Src="UserControl/ucSysFuncOperates.ascx" TagName="ucSysFuncOperates"
    TagPrefix="uc1" %>
<%@ Register Assembly="Auto.WebControls" Namespace="Auto.WebControls" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentMain" runat="server">

    <script src="../_System/Script/Common.js" type="text/javascript"></script>

    <div class="TitleDivStyle">
        <asp:Label ID="Label1" runat="server" Text="<%$Resources:Base,SysFuncOperate%>"></asp:Label></div>
    <table border="0" cellpadding="0" cellspacing="2" style="width: 100%;">
        <tr>
            <td nowrap="nowrap" style="height: 217px" valign="top">
                <table>
                    <tr>
                        <td valign="top" class="borderStyle">
                            <div id="TreeDiv" class="overStyle" style="width: 200px;">
                                <uc1:ucSysFuncOperates ID="ucSysFuncOperates1" runat="server" />
                            </div>
                        </td>
                        <td valign="top">
                            <div style="border: solid 1px  #4682b4; padding: 1px;" class="overStyle" runat="server"
                                id="divGridView">
                                <asp:GridView ID="gv" runat="server" AutoGenerateColumns="False" AllowSorting="True"
                                    PageSize="20" CssClass="GridViewStyle" OnRowCommand="gv_RowCommand" OnRowDataBound="gv_RowDataBound"
                                    AllowPaging="True" OnPageIndexChanging="gv_PageIndexChanging">
                                    <Columns>
                                        <asp:TemplateField HeaderText="<%$ Resources:Base,SysID %>">
                                            <ItemTemplate>
                                                <asp:Label ID="lblSysID" runat="Server" Text='<%# DataBinder.Eval(Container.DataItem, SysFunctions.FIELD_SysID)%>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="<%$ Resources:Base,FuncID %>">
                                            <ItemTemplate>
                                                <asp:Label ID="lblFuncID" runat="Server" Text='<%# DataBinder.Eval(Container.DataItem, SysFunctions.FIELD_FuncID)%>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="<%$ Resources:Base,FuncName %>">
                                            <ItemTemplate>
                                                <asp:Label ID="lblFuncName" runat="Server" Text='<%# DataBinder.Eval(Container.DataItem, SysFunctions.FIELD_FuncName)%>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="<%$ Resources:Base,OperateList %>">
                                            <ItemTemplate>
                                                <asp:CheckBoxList ID="chkOperateList" runat="server" RepeatDirection="Horizontal">
                                                </asp:CheckBoxList>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Edit">
                                            <ItemTemplate>
                                                <asp:LinkButton ID="lnkUpdate" Text="Update" runat="Server" CommandName="OperateUpdate"
                                                    CommandArgument='<%# Container.DisplayIndex %>'></asp:LinkButton>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                    <FooterStyle CssClass="GridViewFooterStyle" />
                                    <RowStyle CssClass="GridViewRowStyle" />
                                    <EditRowStyle CssClass="GridViewEditRowStyle" />
                                    <SelectedRowStyle CssClass="GridViewSelectedRowStyle" />
                                    <PagerStyle CssClass="GridViewPagerStyle"  />
                                    <HeaderStyle CssClass="GridViewHeaderStyle" />
                                    <AlternatingRowStyle CssClass="GridViewAlternatingRowStyle" />
                                </asp:GridView>
                                <asp:Button ID="btnSave" runat="server" CssClass="button_bak" Text="Save All" OnClick="btnSave_Click" />
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>

    <script type="text/javascript">
    var Class = {
      create: function() {
        return function() {
          this.initialize.apply(this, arguments);
        }
      }
    }
    var extend = function(destination, source) {
      for (var property in source) {
        destination[property] = source[property];
      }
      return destination;
    }
    var TableSorter =  Class.create();//表格排序器
    TableSorter.prototype = {
      initialize:function(options){//★★入口函数兼构造函数★★
        this.setOptions(options);
        this.sortTable(this.options.table_id);
      },
      setOptions:function(options){
        this.options = { //这里集中设置默认属性
          table_id:null//必选项
        };
        extend(this.options, options || {});//这里是用来重写默认属性
      },
      ID:function(id){return document.getElementById(id) },//getElementById的快捷方式
      CE:function(tag){return document.createElement(tag) },//getElementById的快捷方式
      TN:function(){//getElementsByTagName的快捷方式
        if(arguments.length == 1){
          return document.getElementsByTagName(arguments[0])
        } else if(arguments.length == 2){
          return arguments[0].getElementsByTagName(arguments[1])
        }
      },
      sortTable:function(id){//★★核心函数，所有方法在这时集中调用★★
        var $ = this,
        table = $.ID(id);
        if(table == null){ throw "this table is inexistence!"; return };
        var tbody = $.TN(table,"tbody")[0],
        rows = $.TN(tbody,"tr"),
        up = $.CE("span"),
        index = [];
        //  把要排序的行的引用放到index数组中。
        for (var i=0,l = rows.length; i < l; i++) {
          index[i] = rows[i];
        }
        up.style.cssText = "font:normal lighter 1em/100% sans-serif;color:#f00;background:#A9EA00;";
        up.innerHTML = "↑"
        var down = up.cloneNode(true);
        down.innerHTML = "↓"
        table.onclick = function(){
          var e = arguments[0] || window.event,
          th = e.srcElement ? e.srcElement : e.target,
          thn = th.nodeName.toLowerCase(),
          theadn = th.parentNode.parentNode.nodeName.toLowerCase();
          if(thn == 'th' && theadn == 'thead'){
            var colIndex = th.cellIndex;
            $.colsStatus[colIndex] = ($.colsStatus[colIndex] == null) ? 1 : $.colsStatus[colIndex] * -1;
            index.sort($.sortby(colIndex,$));
            if($.colsStatus[colIndex] > 0){
              th.appendChild(up);
              if(th.innerHTML.toLowerCase().search(/↓/) != -1){
                th.removeChild(down);
              }
            }else{
              th.appendChild(down);
              if(th.innerHTML.toLowerCase().search(/↑/) != -1){
                th.removeChild(up);
              }
            }
           window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
            var fragment = document.createDocumentFragment();
            for(var i=0,l = index.length; i < l; i++) {
              fragment.appendChild(index[i]);
            }
            tbody.appendChild(fragment);
            for(var i=0 ,l = $.checkedElements.length;i< l; i++){
              $.checkedElements[i].checked = true;
            }
          }
        }
      } ,
      checkedElements:[],
      colsStatus:[],
      sortby : function (colIndex,$) {
        var _cellIndex = colIndex;
        return function (row1, row2) {
          var value1 = $.format(row1.cells[_cellIndex].innerHTML),
          value2 = $.format(row2.cells[_cellIndex].innerHTML),
          result = 0;
          switch(typeof value1){
            case "string":
              result = value1.localeCompare(value2);
              break;
            case "number" :
              result = value1 - value2;
              break;
            case "boolean" : /*处理radio与checkbox*/
              var input1 = $.TN(row1.cells[_cellIndex],'input')[0];
              value1 = input1.checked;
              value1 = (value1 == true) ? 1 :0;
              if(value1){
                $.checkedElements.push(input1);
              }
              value2 = $.TN(row2.cells[_cellIndex],'input')[0].checked;
              value2 = (value2 == true) ? 1 :0;
              result = value1 - value2;
              break;
          }
          result *=  $.colsStatus[_cellIndex];
          return result;
        };
      },
      format : function(s){
        if(/^\d+$/.test(s)){/*如果是正整数*/
          return parseInt(s,10)/*确保它的类型为number*/
        }else if(/^(-?\d+)(\.\d+)$/.test(s)){/*如果是浮点数*/
          return parseFloat(s, 10)/*确保它的类型为number*/
        }else if(/^(\d{4})-(\d{1,2})-(\d{1,2})$/.test(s)){/*如果是日期*/
          return Date.parse(s.replace(/\-/g, '/'));/*确保它的类型为number*/
        }else if(/\%$/.test(s)){/*如果是百分数*/
          return Number(s.replace("%", ""));/*确保它的类型为number*/
        }else if(s.toLowerCase().search(/(type=)"?(radio)"?/)!=-1){
          return true;/*确保它的类型为boolean*/
        }else if(s.toLowerCase().search(/(type=)"?(checkbox)"?/)!=-1){
          return false;/*确保它的类型为boolean*/
        } else {/*如果是字符串*/
          return s.toUpperCase()
        };
      }

    }

    window.onload = function(){
        var gv = document.getElementById("ctl00_ContentMain_gv");
        if(gv != null)
        {
            new TableSorter({table_id:"ctl00_ContentMain_gv"});
        }
    }

//        function adjustSize()
//        {
//            var setheight=document.documentElement.offsetHeight-38;
//            if(setheight>0)
//            {
//                document.getElementById("TreeDiv").style.height=setheight+"px";
//                var divgridview=document.getElementById("<%=divGridView.ClientID%>");
//                var setwidth=document.documentElement.offsetWidth-220;
//                if(divgridview!=null&&setwidth>0)
//                {
//                    divgridview.style.height=setheight+"px";
//                    divgridview.style.width=setwidth+"px";
//  
//                }
//            }
//        }
//        window.onload=function()
//        {
//            adjustSize();            
//        }
//        window.onresize=function()
//        {
//            adjustSize();
//        }
        
        window.onload=function()
        {
            setHeight("TreeDiv",-38);
            setHeight("<%=divGridView.ClientID%>",-38);
            setWidth("<%=divGridView.ClientID%>",-220);            
        }
        window.onresize=function()
        {
            setHeight("TreeDiv",-38);
            setHeight("<%=divGridView.ClientID%>",-38);
            setWidth("<%=divGridView.ClientID%>",-220);  
        }
       
    </script>

</asp:Content>
